"""
选择最小元素依次放在序列前端
"""
import random


def selectSort(nums):

    if not nums:
        return nums

    for i in range(1, len(nums)):
        min_index = i - 1
        for j in range(i, len(nums)):
            if nums[j] < nums[min_index]:
                min_index = j
        if min_index != i - 1:
            nums[i-1], nums[min_index] = nums[min_index], nums[i-1]

    return nums


if __name__ == '__main__':
    ls = [random.randint(1, 100) for _ in range(10)]
    print(ls)
    print(selectSort(ls))
